<?php
/**
 * 主导航菜单组件
 */
    namespace app\commands\background;
    use app\modules\admin\models\Node;
    use app\modules\admin\models\Role;
    use yii\base\Widget;
    use yii;;
    use app\models\Block;
	class NavWidget extends Widget  {
        public $data;
        public $navData;
        public $blockArr = [];
        /**
         * 定义函数
         * */
        public function init()
        {//这个可以取侧边栏数
            $rid  =  Yii::$app->session->get('rid');
            $ids=  Yii::$app->db->createCommand("select ids from {{%role}} where id=$rid")->queryOne();
            $node= $ids!=false?Node::find()->distinct()->select('module')->asArray()->where('id in ('.$ids['ids'].')')->all():array();
            $this->navData = $node!=false?array_column($node,'module'):array();
        }

        /**
         * 运行覆盖程序
         * */
        public function run(){
            return $this->render('nav',['data' => $this->data,'navData' => $this->navData,'blockArr' => $this->blockArr]);
        }
	}
?>